
package org.idea.spring.aop.cglib.fastclass;

import org.idea.spring.aop.cglib.MyBis;
import org.idea.spring.aop.cglib.proxy.MyBisMethodInterceptorImpl;
import org.idea.spring.aop.cglib.proxy.MyEnhancer;
import org.idea.spring.aop.cglib.proxy.MyMethodProxy;

/**
 * 基于fastClass的机制来触发函数调用的功能
 */
public class MyBisFastClass implements MyMethodProxy {

    private Object invoke(int index, Object object, Object[] param) {
        MyBis myBis = (MyBis) object;
        switch (index) {
            case 1:
                myBis.doBus();
                return null;
            default:
                return null;
        }
    }

    private int getIndex(String methodInput) {
        switch (methodInput.hashCode()) {
            case 95726069:
                return 1;
        }
        return -1;
    }


    @Override
    public Object invokeSuper(Object object, Object[] params) {
        int index = getIndex("doBus");
        return this.invoke(index, object, params);
    }

    public static void main(String[] args) {
        MyEnhancer myEnhancer = new MyEnhancer();
        myEnhancer.setSource(new MyBis());
        myEnhancer.setMyMethodInterceptor(new MyBisMethodInterceptorImpl());
        MyBis myBis = myEnhancer.create();
        myBis.doBus();
    }


}
